原来用的一个分页,速度太慢了(后面的页),就搞了这个出来 此代码在MS SQL下通过 topic_endtime为最后回复时间,主建、降序,Clustered
Dim PageSizer,CurrentPage,Board_Id,End_Id
'// 这就是当前页码,可以随便你怎么跳 CurrentPage = Clng(Request("page"))
'// 每页显示PageSize条记录 PageSizer = 20
'// 分论坛的ID Board_Id = Cint(Request("id"))
'// 就是靠这个做条件了 End_Id = (CurrentPage - 1) * PageSizer
sql = "Select top "&PageSizer&" * From [topic] where topic_boardid="&Board_Id&" and topic_endtime<(Select Min(topic_endtime) as topic_endtime From (Select top "&End_Id&" topic_endtime From [topic] where topic_boardid="&Board_Id&") as temp_topic)"
原理就是取出你要读取的记录的上面那些记录,然后就在这个集合里面用Min(topic_endtime),因为topic_endtime原来已经排序好了,所以取最小的topic_endtime,然后你要读取的记录的topic_endtime值都比这个topic_endtime要小,再top PageSizer就是你要取的记录了
补充:在第一页用top PageSizer
PS:在50万的记录,最后一页都是15ms, 测试机器:Duron 1G + 256 sdram 在服务器上最快是5ms |